import 'package:flutter/material.dart';

class MyApp9 extends StatelessWidget {
  // 2. 设置默认值
  const MyApp9({
    super.key,
    this.title = '',
    this.content = '',
    this.tColor = Colors.orange,
    this.cColor = Colors.yellow,
  });

  // 1. 定义属性
  final String title;
  final String content;
  final Color tColor;
  final Color cColor;

  // 重写build 返回需要封装的组件即可
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.purple,
          title: Center(
            child: Text(
              '标题为:$title',
              style: TextStyle(
                  color: tColor, fontSize: 30, fontWeight: FontWeight.w900),
            ),
          ),
        ),
        // 1.2 主体部分
        body: const MyContainer(),
      ),
    );
  }
}

class MyContainer extends StatelessWidget {
  const MyContainer({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Stack(
        // 对齐
        alignment: AlignmentDirectional.center,
        // 超出的内容是否需要显示
        clipBehavior: Clip.none,
        children: [
          Container(
            width: 300,
            height: 300,
            color: Colors.blueAccent,
          ),
          Positioned(
            top: -100,
            child: Image.asset('open_eyes.png'),
          ),
          Image.network(
              'http://tiebapic.baidu.com/forum/w%3D580/sign=442164a889bf6c81f7372ce08c3cb1d7/f20ab519367adab4924e9b83ced4b31c8601e46d.jpg')
        ],
      ),
    );
  }
}
